*******
**# Import the full list of raw Health Care Provider Taxonomy Codes 

import delimited "${raw_data}/crosswalks/specialty/nucc_taxonomy_181.csv", varnames(1) clear

rename code PROVIDERTAXONOMYCODE

* Keep codes corresponding to "Allopathic & Osteopathic Physicians"

keep if regexm(grouping, "Allopathic & Osteopathic Physicians")

tempfile phys_taxonomy
save "`phys_taxonomy'"

* Crosswalk Health Care Provider Taxonomy Codes to Medicare Specialty Codes

import excel "${raw_data}/crosswalks/specialty/CROSSWALK_MEDICARE_PROVIDER_SUPPLIER_to_HEALTHCARE_PROVIDER_TAXONOMY.xlsx", sheet("CROSSWALK_MEDICARE_PROVIDER_SUP") firstrow  clear

drop if mi(PROVIDERTAXONOMYCODE)
merge m:1 PROVIDERTAXONOMYCODE using "`phys_taxonomy'", keep(matched using) nogen

compress

replace MEDICARESPECIALTYCODE = "21" if PROVIDERTAXONOMYCODE == "207RC0001X"
drop if PROVIDERTAXONOMYCODE=="204C00000X" & MEDICARESPECIALTYCODE=="12"
drop if PROVIDERTAXONOMYCODE=="204E00000X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207L00000X" & MEDICARESPECIALTYCODE=="79"
drop if PROVIDERTAXONOMYCODE=="207LH0002X" & MEDICARESPECIALTYCODE=="17"
drop if PROVIDERTAXONOMYCODE=="207LH0002X" & MEDICARESPECIALTYCODE=="17"
drop if PROVIDERTAXONOMYCODE=="207PH0002X" & MEDICARESPECIALTYCODE=="17"
drop if PROVIDERTAXONOMYCODE=="207PS0010X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="207PT0002X" & MEDICARESPECIALTYCODE=="C8"
drop if PROVIDERTAXONOMYCODE=="207QA0401X" & MEDICARESPECIALTYCODE=="79"
drop if PROVIDERTAXONOMYCODE=="207QG0300X" & MEDICARESPECIALTYCODE=="38"
drop if PROVIDERTAXONOMYCODE=="207QG0300X" & MEDICARESPECIALTYCODE=="27"
drop if PROVIDERTAXONOMYCODE=="207QH0002X" & MEDICARESPECIALTYCODE=="17"
drop if PROVIDERTAXONOMYCODE=="207QS0010X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="207QS1201X" & MEDICARESPECIALTYCODE=="C0"
drop if PROVIDERTAXONOMYCODE=="207RA0001X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RA0401X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RC0000X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RC0200X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RE0101X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RG0100X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RG0300X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RH0000X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RH0002X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RH0003X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RI0200X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RN0300X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RP1001X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RR0500X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RP1001X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RS0010X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RS0012X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207RX0202X" & MEDICARESPECIALTYCODE=="11"
drop if PROVIDERTAXONOMYCODE=="207T00000X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207VH0002X" & MEDICARESPECIALTYCODE=="16"
drop if PROVIDERTAXONOMYCODE=="207VX0201X" & MEDICARESPECIALTYCODE=="16"
drop if PROVIDERTAXONOMYCODE=="207X00000X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XP3100X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XS0106X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XS0114X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XS0117X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XX0004X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XX0005X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207XX0005X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="207XX0801X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="207YS0012X" & MEDICARESPECIALTYCODE=="C0"
drop if PROVIDERTAXONOMYCODE=="2080S0010X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="2080S0012X" & MEDICARESPECIALTYCODE=="C0"
drop if PROVIDERTAXONOMYCODE=="2081S0010X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="208200000X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="2082S0099X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="24"
drop if PROVIDERTAXONOMYCODE=="2082S0105X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="2083S0010X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="2084A0401X" & MEDICARESPECIALTYCODE=="79"
drop if PROVIDERTAXONOMYCODE=="2084H0002X" & MEDICARESPECIALTYCODE=="17"
drop if PROVIDERTAXONOMYCODE=="2084N0400X" & MEDICARESPECIALTYCODE=="13"
drop if PROVIDERTAXONOMYCODE=="2084N0402X" & MEDICARESPECIALTYCODE=="86"
drop if PROVIDERTAXONOMYCODE=="2084P0800X" & MEDICARESPECIALTYCODE=="86"
drop if PROVIDERTAXONOMYCODE=="2084S0010X" & MEDICARESPECIALTYCODE=="23"
drop if PROVIDERTAXONOMYCODE=="2084S0012X" & MEDICARESPECIALTYCODE=="C0"
drop if PROVIDERTAXONOMYCODE=="2086H0002X" & MEDICARESPECIALTYCODE=="17"
drop if PROVIDERTAXONOMYCODE=="2086S0105X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="2086S0105X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="2086S0129X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="2086S0129X" & MEDICARESPECIALTYCODE=="77"
drop if PROVIDERTAXONOMYCODE=="2086X0206X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="208C00000X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="208D00000X" & MEDICARESPECIALTYCODE=="99"
drop if PROVIDERTAXONOMYCODE=="208G00000X" & MEDICARESPECIALTYCODE=="2"
drop if PROVIDERTAXONOMYCODE=="208G00000X" & MEDICARESPECIALTYCODE=="33"

gen missing_cms = 1 if mi(MEDICARESPECIALTYCODE)

replace MEDICARESPECIALTYCODE = "11" if classification == "Internal Medicine" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Internal Medicine" if classification == "Internal Medicine" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "22" if classification == "Pathology" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Pathology" if classification == "Pathology" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "30" if classification == "Radiology" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Diagnostic Radiology" if classification == "Radiology" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "37" if classification == "Pediatrics" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Pediatric Medicine" if classification == "Pediatrics" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "84" if classification == "Preventive Medicine" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Preventive Medicine" if classification == "Preventive Medicine" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "86" if classification == "Psychiatry & Neurology" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Neuropsychiatry" if classification == "Psychiatry & Neurology" & missing_cms == 1
		
replace MEDICARESPECIALTYCODE = "U4" if classification == "Phlebology" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Phlebology" if classification == "Phlebology" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "U5" if classification == "Electrodiagnostic Medicine" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Electrodiagnostic Medicine" if classification == "Electrodiagnostic Medicine" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "U1" if classification == "Medical Genetics" & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Genetics" if classification == "Medical Genetics" & missing_cms == 1

replace MEDICARESPECIALTYCODE = "U2" ///
	if inlist(classification,"Pharmacology", "Legal Medicine", "Physician/Back Office", "Medical Examiner", "Pharmacology", "Legal Medicine", "Independent Medical Examiner", "Clinical Pharmacology") & missing_cms == 1
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Back Office" ///
	if inlist(classification,"Pharmacology", "Legal Medicine", "Physician/Back Office", "Medical Examiner", "Pharmacology", "Legal Medicine", "Independent Medical Examiner", "Clinical Pharmacology") & missing_cms == 1
	
replace MEDICARESPECIALTYCODE = "0" + MEDICARESPECIALTYCODE if strlen(MEDICARESPECIALTYCODE) == 1
replace MEDICARESPECIALTYCODE = "U3" if PROVIDERTAXONOMYCODE == "207RH0005X"
replace MEDICAREPROVIDERSUPPLIERTYPE = "Physician/Hypertension Specialist" if PROVIDERTAXONOMYCODE == "207RH0005X"


* Crosswalk Medicare Specialty Codes to specialty categories

gen spec_category_code = . 
gen spec_category_desc = ""

** 1: Primary Care **

foreach sp in 01 08 11 17 23 26 37 38 79 84 C0 72 {
	replace spec_category_code = 1 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Primary Care" if MEDICARESPECIALTYCODE == "`sp'"
}

** 2: Medicine Subspecialty **

foreach sp in 03 06 10 21 29 39 44 46 66 81 82 83 90 91 C3 C7 U1 U3 U4 {
	replace spec_category_code = 2 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Medicine Subspecialty" if MEDICARESPECIALTYCODE == "`sp'"
}

** 3: Ob/Gyn **

foreach sp in 16 98 {
	replace spec_category_code = 3 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Ob/Gyn" if MEDICARESPECIALTYCODE == "`sp'"
}

** 4: Surgery **

foreach sp in 02 14 20 24 28 33 40 76 78 85 {
	replace spec_category_code = 4 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Surgery" if MEDICARESPECIALTYCODE == "`sp'"
}

** 5: Procedural Specialties **

foreach sp in 04 07 18 34 {
	replace spec_category_code = 5 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Procedural Specialties" if MEDICARESPECIALTYCODE == "`sp'"
}

** 6: Hospital-Based **

foreach sp in 22 25 93 C6 U2 {
	replace spec_category_code = 6 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Hospital-Based" if MEDICARESPECIALTYCODE == "`sp'"
}

** 7: Anesthesiology **

foreach sp in 05 09 {
	replace spec_category_code = 7 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Anesthesiology" if MEDICARESPECIALTYCODE == "`sp'"
}

** 8: Radiology **

foreach sp in 30 36 92 94 {
	replace spec_category_code = 8 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Radiology" if MEDICARESPECIALTYCODE == "`sp'"
}

** 9: Neurology **

foreach sp in 12 13 86 U5 {
	replace spec_category_code = 9 if MEDICARESPECIALTYCODE == "`sp'"
	replace spec_category_desc = "Neurology" if MEDICARESPECIALTYCODE == "`sp'"
}

* Crosswalk Medicare Specialty Codes to AAMC specialties

gen aamc_spec_desc = ""
replace aamc_spec_desc = "Allergy and Immunology"				if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Allergy/ Immunology"
replace aamc_spec_desc = "Anatomic/Clinical Pathology"			if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Pathology"
replace aamc_spec_desc = "Anesthesiology"						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Anesthesiology"
replace aamc_spec_desc = "Cardiovascular Disease"				if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Cardiovascular Disease (Cardiology)"
replace aamc_spec_desc = "Critical Care Medicine"				if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Critical Care (Intensivists)"
replace aamc_spec_desc = "Dermatology" 							if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Dermatology"
replace aamc_spec_desc = "Emergency Medicine" 					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Emergency Medicine"
replace aamc_spec_desc = "Endocrinology Diabetes and Metabolism" if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Endocrinology"
replace aamc_spec_desc = "Family Medicine/General Practice" 		if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Family Practice" 		| MEDICAREPROVIDERSUPPLIERTYPE == "Physician/General Practice"
replace aamc_spec_desc = "Gastroenterology" 						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Gastroenterology"
replace aamc_spec_desc = "General Surgery"						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/General Surgery"
replace aamc_spec_desc = "Geriatric Medicine"					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Geriatric Medicine"
replace aamc_spec_desc = "Hematology and Oncology"				if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Hematology-Oncology"
replace aamc_spec_desc = "Infectious Disease" 					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Infectious Disease"
replace aamc_spec_desc = "Internal Medicine"						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Internal Medicine" 		
replace aamc_spec_desc = "Interventional Cardiology" 			if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Interventional Cardiology"
replace aamc_spec_desc = "Nephrology"							if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Nephrology"
replace aamc_spec_desc = "Neurological Surgery"					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Neurosurgery"
replace aamc_spec_desc = "Neurology"								if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Neurology"
replace aamc_spec_desc = "Obstetrics and Gynecology"				if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Obstetrics & Gynecology"
replace aamc_spec_desc = "Ophthalmology"							if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Ophthalmology"
replace aamc_spec_desc = "Orthopedic Surgery"					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Orthopedic Surgery"
replace aamc_spec_desc = "Otolaryngology"						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Otolaryngology"
replace aamc_spec_desc = "Pain Medicine and Pain Management"		if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Pain Management"
replace aamc_spec_desc = "Pediatrics"							if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Pediatric Medicine"
replace aamc_spec_desc = "Physical Medicine and Rehabilitation"	if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Physical Medicine and Rehabilitation"
replace aamc_spec_desc = "Plastic Surgery"						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Plastic and Reconstructive Surgery"
replace aamc_spec_desc = "Preventive Medicine"					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Preventive Medicine"
replace aamc_spec_desc = "Psychiatry"							if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Psychiatry"
replace aamc_spec_desc = "Pulmonary Disease"						if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Pulmonary Disease"
replace aamc_spec_desc = "Radiation Oncology"					if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Radiation Oncology"
replace aamc_spec_desc = "Radiology and Diagnostic Radiology" 	if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Diagnostic Radiology" 
replace aamc_spec_desc = "Rheumatology"							if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Rheumatology"
replace aamc_spec_desc = "Sports Medicine (Orthopedic Surgery)"	if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Sports Medicine"
replace aamc_spec_desc = "Urology"								if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Urology"
replace aamc_spec_desc = "Vascular and Interventional Radiology"	if MEDICAREPROVIDERSUPPLIERTYPE == "Physician/Interventional Radiology"


* Crosswalk Medicare Specialty Codes to NRMP specialties

gen nrmp_spec_desc  = ""
replace nrmp_spec_desc  = "Family Medicine" if MEDICARESPECIALTYCODE == "01"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "02"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "03"
replace nrmp_spec_desc  = "Otolaryngology" if MEDICARESPECIALTYCODE == "04"
replace nrmp_spec_desc  = "Anesthesiology" if MEDICARESPECIALTYCODE == "05"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "06"
replace nrmp_spec_desc  = "Dermatology" if MEDICARESPECIALTYCODE == "07"
replace nrmp_spec_desc  = "Family Medicine" if MEDICARESPECIALTYCODE == "08"
replace nrmp_spec_desc  = "Anesthesiology" if MEDICARESPECIALTYCODE == "09"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "10"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "11"
replace nrmp_spec_desc  = "Family Medicine" if MEDICARESPECIALTYCODE == "12"
replace nrmp_spec_desc  = "Neurology" if MEDICARESPECIALTYCODE == "13"
replace nrmp_spec_desc  = "Neurological Surgery" if MEDICARESPECIALTYCODE == "14"
replace nrmp_spec_desc  = "ObGyn" if MEDICARESPECIALTYCODE == "16"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "17"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "18"
replace nrmp_spec_desc  = "Orthopaedic Surgery" if MEDICARESPECIALTYCODE == "20"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "21"
replace nrmp_spec_desc  = "Pathology" if MEDICARESPECIALTYCODE == "22"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "23"
replace nrmp_spec_desc  = "Plastic Surgery" if MEDICARESPECIALTYCODE == "24"
replace nrmp_spec_desc  = "Physical Medicine and Rehabilitation" if MEDICARESPECIALTYCODE == "25"
replace nrmp_spec_desc  = "Psychiatry" if MEDICARESPECIALTYCODE == "26"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "28"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "29"
replace nrmp_spec_desc  = "Radiology" if MEDICARESPECIALTYCODE == "30"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "34"
replace nrmp_spec_desc  = "Radiology" if MEDICARESPECIALTYCODE == "36"
replace nrmp_spec_desc  = "Pediatrics" if MEDICARESPECIALTYCODE == "37"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "38"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "39"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "40"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "44"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "46"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "66"
replace nrmp_spec_desc  = "Anesthesiology" if MEDICARESPECIALTYCODE == "72"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "76"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "78"
replace nrmp_spec_desc  = "Psychiatry" if MEDICARESPECIALTYCODE == "79"
replace nrmp_spec_desc  = "Emergency Medicine" if MEDICARESPECIALTYCODE == "81"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "82"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "83"
replace nrmp_spec_desc  = "Family Medicine" if MEDICARESPECIALTYCODE == "84"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "85"
replace nrmp_spec_desc  = "Psychiatry" if MEDICARESPECIALTYCODE == "86"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "90"
replace nrmp_spec_desc  = "Surgery" if MEDICARESPECIALTYCODE == "91"
replace nrmp_spec_desc  = "Radiation Oncology" if MEDICARESPECIALTYCODE == "92"
replace nrmp_spec_desc  = "Emergency Medicine" if MEDICARESPECIALTYCODE == "93"
replace nrmp_spec_desc  = "Radiology" if MEDICARESPECIALTYCODE == "94"
replace nrmp_spec_desc  = "ObGyn" if MEDICARESPECIALTYCODE == "98"
replace nrmp_spec_desc  = "Neurology" if MEDICARESPECIALTYCODE == "C0"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "C3"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "C6"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "C7"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "U1"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "U2"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "U3"
replace nrmp_spec_desc  = "Internal Medicine" if MEDICARESPECIALTYCODE == "U4"
replace nrmp_spec_desc  = "Neurology" if MEDICARESPECIALTYCODE == "U5"

egen nrmp_spec_code = group(nrmp_spec_desc)

label variable nrmp_spec_desc "NRMP Specialty"
label variable nrmp_spec_code "NRMP Specialty"

keep MEDICARESPECIALTYCODE MEDICAREPROVIDERSUPPLIERTYPE PROVIDERTAXONOMYCODE PROVIDERTAXONOMYDESCRIPTION spec_category_code spec_category_desc aamc_spec_desc nrmp_spec_code nrmp_spec_desc

rename PROVIDERTAXONOMYCODE 		pr_taxonomy_code
rename MEDICARESPECIALTYCODE		cms_spec_code
rename PROVIDERTAXONOMYDESCRIPTION 	pr_taxonomy_desc
rename MEDICAREPROVIDERSUPPLIERTYPE 	cms_spec_desc

order pr_taxonomy_code pr_taxonomy_desc cms_spec_code cms_spec_desc aamc_spec_desc spec_category_code spec_category_desc nrmp_spec_code nrmp_spec_desc

sort pr_taxonomy_code cms_spec_code spec_category_code nrmp_spec_code nrmp_spec_desc

isid pr_taxonomy_code

save "${intermediate_data}/crosswalks/recoded_specialty_crosswalk.dta", replace
